package com.hooper.project.rpc;

import com.hooper.api.common.model.InterfaceInfoDto;
import com.hooper.api.common.service.InterfaceInfoService4Dubbo;
import com.hooper.project.model.entity.InterfaceInfo;
import com.hooper.project.service.InterfaceInfoService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author Tim Hooper
 * @version 1.0
 * @time 2023/04/13/0:13
 */
@DubboService(timeout = 2000)
@Component
public class InterfaceInfoService4DubboImpl implements InterfaceInfoService4Dubbo {
    @Resource
    private InterfaceInfoService interfaceInfoService;
    @Override
    public InterfaceInfoDto getInterfaceInfoByUrlAndMethod(String url, String method) {
        if (StringUtils.isAnyBlank(url, method)) {
            return null;
        }
        InterfaceInfo interfaceInfo = interfaceInfoService.getInterfaceInfoByUrlAndMethod(url, method);
        if (interfaceInfo == null) {
            return null;
        }
        InterfaceInfoDto interfaceInfoDto = new InterfaceInfoDto();
        BeanUtils.copyProperties(interfaceInfo, interfaceInfoDto);
        return interfaceInfoDto;
    }
}
